package com.third.customer.service.utils;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;

import java.util.List;

/**
 * 分页返回数据
 *Created by hehuaichun on 2020/5/24.
 */
@Data
public class PageResult<T> {

    /**
     * 总数
     */
    private long total = 0;
    /**
     * 每页显示条数，默认 10
     */
    private long size = 10;

    /**
     * 当前页
     */
    private long current = 1;

    private boolean hasNext = false;

    private List<T> data;

    public static <T> PageResult<T> build(Page<T> page) {
        return build(page, page.getRecords());
    }

    public static <T> PageResult<T> build(Page page, List<T> data) {
        PageResult<T> result = new PageResult<>();
        result.setTotal(page.getTotal());
        result.setCurrent(page.getCurrent());
        result.setSize(page.getSize());
        result.setData(data);
        result.setHasNext(page.hasNext());
        return result;
    }
}
